#ifndef _TAB_FILE_EDIT_H_
#define _TAB_FILE_EDIT_H_

#include <string>
#include <vector>
#include <map>

enum COLUMN_TYPE
{
	ctInvalid = 0,

	ctNumber,
	ctEnum,
	ctString,
	ctRichText,
	ctID,

	ctTotal
};

struct COLUMN_CONFIG
{
	std::string											strName;
	std::string											strDefault;
	int													nColumnType;
	int													nMin;
	int													nMax;
	std::string											strLinkTable;
	std::string											strLinkColumn;
	std::string											strDisplayColumn;
	std::string											strGroup;
	std::map<int, std::string>							mapID2String;
	std::map<std::string, int, std::less<std::string>>	mapString2ID;
};

class BASELIB_API CTabFileEdit
{
public:
	CTabFileEdit();
	~CTabFileEdit();

	bool Init(const char* pcszFileName);
	bool UnInit(void);

	bool Save(void);

	int GetRowCount(void);
	int GetColCount(void);

	const char* GetData(int nCol, int nRow);
	const char* GetData(const char* pcszColName, int nRow);

	const COLUMN_CONFIG* GetConfig(int nCol);

	bool AppendRow(void);
	bool DeleteRow(int nRowIndex);

	bool SetData(int nCol, int nRow, const char* pcszValue);
	bool SetData(const char* pcszColName, int nRow, const char* pcszValue);

private:
	bool _LoadConfig(const char* pcszFileName);

private:
	char								m_szFileName[MAX_FILE_NAME_LEN];
	std::vector<std::vector<std::string>>	m_Data;
	int									m_nRowCount;
	int									m_nColCount;

	typedef std::map<std::string, int, std::less<std::string>> MAP_NAME_2_COL;
	MAP_NAME_2_COL				m_mapName2Col;

	typedef std::vector<COLUMN_CONFIG>	VEC_COLUMN_CONFIG;
	VEC_COLUMN_CONFIG			m_vecColumnConfig;

};

#endif	// _TAB_FILE_EDIT_H_